package com.elementum.olegomatic.dictionaries;

import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created with IntelliJ IDEA.
 * User: jmp
 * Date: 10/9/13
 * Time: 7:12 PM
 * To change this template use File | Settings | File Templates.
 */
public enum DictId {
    Sites("site"){
        @Override
        public DBObject getQuery() {
            // {$project : {"keyword":"$site"}
            DBObject r = new BasicDBObject();
            DBObject prj = new BasicDBObject();
            prj.put("keyword", "$site");
            r.put("$project", prj);
            return r;
        }
    }, Events("keywords"){
            @Override
            public DBObject getQuery() {
                // {$unwind: "$keywordsOr"}, {$project: {keyword: "$keywordsOr.key"}}
                BasicDBList arr = new BasicDBList();
                DBObject r = new BasicDBObject();
                DBObject unwind = new BasicDBObject();
                unwind.put("$unwind", "$keywordsOr");
                DBObject prj = new BasicDBObject();
                prj.put("keyword", "$keywordsOr.key");
                r.put("$project", prj);
                arr.add(unwind);
                arr.add(r);
                return arr;
            }
        };

    private String mongoCollection;
    DictId(String mongoCollection) {
        this.mongoCollection = mongoCollection;
    }
    public abstract DBObject getQuery();

    public String getMongoCollection() {
        return this.mongoCollection;
    }
}
